home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 5_5.lha / 5_5 / 5_5c2.c < prev    next >
Text File  |  1993-08-08  |  829b  |  54 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / print out the tree in postfix format
  6. tatic void postfixprint(tree* head)
  7.  
  8.    if (head)
  9. switch (head->type)
  10.     {
  11.     case PLUS: case DIV: case MUL:
  12.     postfixprint(head->left);
  13.     postfixprint(head->right);
  14.     cout << chr(head->type);
  15.     break;
  16.  
  17.     case MINUS:
  18.     postfixprint(head->left);
  19.     if (head->right)
  20.         {
  21.         postfixprint(head->right);
  22.         cout << "-";
  23.         }
  24.  
  25.     else
  26.         cout << "chg";
  27.     break;
  28.  
  29.     case NUMBER:
  30.     cout << head->value;
  31.     break;
  32.  
  33.     case LP:
  34.     postfixprint(head->left);
  35.     break;
  36.  
  37.     case RP:
  38.     case END:
  39.     default:
  40.     error("invalid type within tree");
  41.     break;
  42.     }
  43.  
  44.    else
  45. error("NULL node found");
  46.  
  47.    cout << " ";
  48.  
  49.  
  50. oid expr:: print()
  51.  
  52.    postfixprint(head);
  53.  
  54.